package com.example.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.entity.Filetype;
import com.example.entity.Filetype1;
import com.example.service.Filetype1Service;
import com.example.service.FiletypeService;
import com.example.service.LogService;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-06-27
 */
@RestController
@RequestMapping("//filetype1")
public class Filetype1Controller {
    @Resource
    private Filetype1Service filetype1Service;
    @Resource
    private LogService logService;
    @Resource
    private HttpServletRequest request;

    @PostMapping
    public Result<?> save(@RequestBody Filetype1 filetype1) {

        return Result.success(filetype1Service.save(filetype1));
    }

    @PutMapping
    public Result<?> update(@RequestBody Filetype1 filetype1) {

        return Result.success(filetype1Service.updateById(filetype1));
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {

        filetype1Service.removeById(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<Filetype1> findById(@PathVariable Long id) {
        return Result.success(filetype1Service.getById(id));
    }

    @GetMapping
    public Result<List<Filetype1>> findAll() {
        return Result.success(filetype1Service.list());
    }
    @GetMapping("/page")
    public Result<IPage<Filetype1>> findPage(@RequestParam(required = false, defaultValue = "") String name,
                                             @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                             @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return Result.success(filetype1Service.page(new Page<>(pageNum, pageSize), Wrappers.<Filetype1>lambdaQuery().like(Filetype1::getFiletype1, name)));
    }
}

